package com.scud.product.feign;

import com.scud.client.product.IProductClient;
import com.scud.model.cart.vo.CartItemVo;
import com.scud.model.order.pojo.OrderDetails;
import com.scud.model.order.vo.ManageOrderVo;
import com.scud.model.order.vo.OrderSkuVo;
import com.scud.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author vermouth
 */
@RestController
@Slf4j
public class ProductClient implements IProductClient {


    @Autowired
    private ProductService productService;

    /**
     * 获取商品信息集合
     *
     * @param orderDetailsList:
     * @return List<OrderSkuVo>
     * @author vermouth
     */
    @Override
    @PostMapping("/api/product/feign/getOrderSkuVoList")
    public List<OrderSkuVo> getOrderSkuVoList(@RequestBody List<OrderDetails> orderDetailsList) {
        log.info("feign远程调用,获取商品信息集合:{}", orderDetailsList);
        List<OrderSkuVo> list = productService.getOrderSkuVoList(orderDetailsList);
        return list;
    }

    /**
     * 根据cartList中每个CartItemVo的skuId补全对应的sku信息
     *
     * @param cartList
     * @return
     */
    @Override
    @PostMapping("/api/product/feign/getCartSku")
    public List<CartItemVo> getCartSku(@RequestBody List<CartItemVo> cartList) {
        log.info("根据cartList中每个CartItemVo的skuId补全对应的sku信息:{}", cartList);
        return productService.getCartSku(cartList);
    }

    /**
     * 恢复sku的库存
     * skuId = skuCount
     *
     * @param skus
     */
    @Override
    @PostMapping("/api/product/feign/resetStock")
    public void resetStock(@RequestBody Map<String, Integer> skus) {
        log.info("恢复sku的库存:{}", skus);
        productService.resetStock(skus);
    }

    /**
     * 获取商家所需要的订单商品信息
     * @param orderDetailsList:
     * @return List<ManageOrderVo>
     * @author vermouth
     */
    @Override
    @PostMapping("/api/product/feign/getManageOrder")
    public List<ManageOrderVo> getManageOrderPage(@RequestBody List<ManageOrderVo> orderDetailsList) {
        log.info("远程调用feign,封装商家所需要的数据");
        List<ManageOrderVo> list=productService.getManageOrderPage(orderDetailsList);
        return list;
    }
}
